---
title: Node.js
---

Univer 具备同构特性，不仅可在浏览器端运行，还能在 Node.js 环境下使用。你可以基于 Univer on Node.js 开发数据处理服务，在服务器端生成或修改文档，并通过 Facade API 与 Univer Sheets 进行交互。

<PlaygroundFrame lang="zh-CN" slug="sheets/node-via-plugin" clickToShow />

Univer on Node.js 与浏览器端的使用方式类似，在预设模式下我们提供开箱即用的预设包；而在插件模式下，你仅需把涉及 UI 的插件排除即可。

### 预设模式

#### 安装

```package-install
npm install @univerjs/preset-sheets-node-core
```

#### 使用

```typescript
import { UniverSheetsNodeCorePreset } from '@univerjs/preset-sheets-node-core' // [!code ++]
import sheetsNodeCoreEnUS from '@univerjs/preset-sheets-node-core/locales/en-US' // [!code ++]
import { createUniver, LocaleType, mergeLocales } from '@univerjs/presets'

async function run(): Promise<void> {
  const { univerAPI } = createUniver({
    locale: LocaleType.ZH_CN,
    locales: {
      [LocaleType.ZH_CN]: mergeLocales(
        sheetsNodeCoreEnUS, // [!code ++]
      ),
    },
    presets: [
      UniverSheetsNodeCorePreset(), // [!code ++]
    ],
  })

  // 你可以在这里任意调用 Facade API 进行文档处理
}

run()
```

### 插件模式

#### 安装

```package-install
npm install @univerjs/core @univerjs/engine-render @univerjs/engine-formula @univerjs/docs @univerjs/sheets @univerjs/sheets-formula @univerjs/sheets-numfmt
```

#### 使用

```typescript
import { LocaleType, mergeLocales, Univer, UniverInstanceType } from '@univerjs/core'
import { FUniver } from '@univerjs/core/facade'
import { UniverDocsPlugin } from '@univerjs/docs'
import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula'
import { UniverRenderEnginePlugin } from '@univerjs/engine-render'
import { UniverSheetsPlugin } from '@univerjs/sheets'
import { UniverSheetsFormulaPlugin } from '@univerjs/sheets-formula'
import { UniverSheetsNumfmtPlugin } from '@univerjs/sheets-numfmt'
import SheetsZhCN from '@univerjs/sheets/locale/zh-CN'

import '@univerjs/engine-formula/facade'
import '@univerjs/sheets/facade'
import '@univerjs/sheets-formula/facade'
import '@univerjs/sheets-numfmt/facade'

const univer = new Univer({
  locale: LocaleType.ZH_CN,
  locales: {
    [LocaleType.ZH_CN]: mergeLocales(
      SheetsZhCN,
    ),
  },
})

univer.registerPlugin(UniverRenderEnginePlugin)
univer.registerPlugin(UniverFormulaEnginePlugin)
univer.registerPlugin(UniverDocsPlugin)
univer.registerPlugin(UniverSheetsPlugin)
univer.registerPlugin(UniverSheetsFormulaPlugin)
univer.registerPlugin(UniverSheetsNumfmtPlugin)

univer.createUnit(UniverInstanceType.UNIVER_SHEET, {})
```
